import Vue from 'vue';
import App from './App.vue';
import { store } from './js/store/newStore.js';
import Blank from "./js/blank.vue";
import Login from "./js/login/login.vue";
import Home from "./js/home/home.vue";
import subHome from "./js/home/subhome/subhome.vue";
import Cutzero from "./js/activity/cutZero.vue";
import subMy from "./js/home/my/my.vue";
import Fruits from "./js/home/nav/fruits.vue";
import Specialty from "./js/home/nav/specialty.vue";
import Dresser from "./js/home/nav/dresser.vue";
import Useday from "./js/home/nav/useday.vue";
import Mother from "./js/home/nav/mother.vue";
import Others from "./js/home/nav/others.vue";
import Detail from "./js/detail/detail.vue";
import Search from "./js/search/search.vue";
import payWrap from "./js/weixin/payWrap.vue";
import A from "./js/collect/collect.vue";
import Allorder from "./js/allorder/allorder.vue";
import Address from "./js/address/address.vue";
import Addaddress from "./js/addAddress/comble.vue";
import Talking from "./js/talking/talking.vue";
import Orderdetail from "./js/orderdetail/orderdetail.vue";
import Talkingnow from "./js/talkingnow/talkingnow.vue";
import Coupon from "./js/coupon/coupon.vue";
import CanUseCoupon from "./js/coupon/canUseconpon.vue";
import Editmy from "./js/editmy/editmy.vue";
import SignIn from "./js/signin/signin.vue";
import Hot from "./js/home/hotlist/hotlist.vue";
import NewProduct from "./js/newProduct/newProduct.vue";
import NewDetail from "./js/newDetail/newDetail.vue";
import HelpCut from "./js/helpCut/helpCut.vue";
import ThreeKan from './js/cutDown/threekan.vue';
import OneKan from './js/cutDown/onekan.vue';
import Openshop from './js/openshop/openshop.vue';
import Business from './js/business/business.vue';
import CutCoin from "./js/cutCoin/cutCoin.vue";
import Rule from "./js/rule/rule.vue";
import Balance from "./js/balance/balance.vue";
import SurplusRule from "./js/surplusRule/rule.vue";
import NewOrder from "./js/newOrder/order.vue";
import AboutBlank from "./js/newOrder/aboutBlank.vue"
import SuccessOrder from "./js/successOrder/success.vue";
import RedBag from "./js/redBag/redBag.vue";
import Sign from "./js/sign/sign.vue";
import RefundPage from "./js/allorder/refund.vue";
import SignGood from "./js/signGood/signGood.vue";
import SignRecord from "./js/signin/signRecord.vue";
import Assess from "./js/assess/assess.vue";
import AssSucc from "./js/assess/assSucc.vue";
import AddTo from "./js/assess/addTo.vue";
import AllAssess from "./js/assess/allAssess.vue";
import Logistics from "./js/logistics/logistics.vue";
import Activity from "./js/talking/activity.vue";
import Flow from "./js/allorder/flow.vue";
import Discuss from "./js/allorder/discuss.vue";
import AllLog from "./js/allorder/allLog.vue";
import Refund from "./js/refund/refund.vue";
import Cutting from "./js/cutting/cutting.vue";
import LookMore from "./js/lookMore/lookMore.vue";
import NewActivity from "./js/newActivity/newActivity.vue";
import ThreeKanRule from "./js/threeKanRule/threeKanRule.vue";
import CutEight from "./js/activity/cutEight.vue";
import CutVoucher from "./js/activity/cutVoucher.vue";
import CutFree from "./js/activity/cutFree.vue";
import Index from "./js/index.vue";
import FreeKan from "./js/cutDown/freeKan.vue";
import KillSecond from "./js/cutDown/killSecond.vue";
import Khh from "./js/share/Khh.vue";
import SwiperUrl from "./js/home/subhome/swiper_url.vue";
import './scss/total.scss';
import Popup from 'mint-ui/lib/popup';
import Loadmore from 'mint-ui/lib/loadmore';

Vue.component(Loadmore.name, Loadmore);
Vue.component(Popup.name, Popup);

Vue.use(VueRouter);
var routes = [{
    path:"/",
    name:"登录",
    component:Login
},{
    path:"/home/index/00",
    name:'home',
    component:resolve=>require(['./js/home/home.vue'],resolve),
    children:[{
        path:"/home/index/00",
        meta: {
            keepAlive: true
        },
        component:subHome,
        name:'首页',
    },{
        path:"/home/newProduct",
        component:NewProduct,
        name:'新品'
    }, {
        path:"/home/hot",
        component:Hot,
        name:'热榜'
    },{
        path:"/home/my",
        component:subMy,
        name:'我的'
    },{
        path:"/home/index/:id",
        component:subHome,
        meta: {
            keepAlive: true
        },
    },{
      path:'/home/khh/:1',
      name:'khh',
      component:Khh
    },{
        path:"/home/fruits/:id",
        component:Fruits,
        name:'水果'
    },
        {
            path:"/home/specialty/:id",
            component:Specialty,
            name:'特产'
        },
        {
            path:"/home/dresser/:id",
            component:Dresser,
            name:'美妆'
        },
        {
            path:"/home/useday/:id",
            component:Useday,
            name:'日用'
        },
        {
            path:"/home/mother/:id",
            component:Mother,
            name:'母婴'
        },
        {
            path:"/home/others/:id",
            component:Others,
            name:'其他'
        },

    ]

},{
    path:"/detail/:id",
    name:"detail",
    component:Detail
},{
    path:"/search",
    name:"search",
    component:Search
},{
    path:"/weixin",
    name:"weixin",
    component:payWrap
},{
    path:"/collect",
    name:"collect",
    component:A
},{
    path:"/allorder",
    name:"我的订单",
    component:Allorder
},{
    path:"/address/:isAddress",
    name:"地址",
    component:Address
},{
    path:"/addAddress/:operate",
    name:"addAddress",
    component:Addaddress
},{
    path:"/talking",
    name:"消息",
    component:Talking
},{
    path:"/orderdetail/:orderid/:type",
    name:"orderdetail",
    component:Orderdetail
},{
    path:"/talkingnow/:catid/:img/:orderid",
    name:"talkingnow",
    component:Talkingnow
},{
    path:"/coupon/:num",
    name:"coupon",
    component:Coupon
},{
    path:"/Canusecoupon/:money",
    name:"can-useconpon",
    component:CanUseCoupon
},
  {
    path:"/editmy",
    name:"editmy",
    component:Editmy
},{
    path:"/signIn/:points",
    name:"signIn",
    component:SignIn
},{
    path:"/newDetail/:pro_id/:type",
    name:"newDetail",
    component:NewDetail
},
{
    path:"/threekan/:shareid",
    name:"threekan",
    component:ThreeKan
}, {
        path:"/oneKan/:shareid",
        name:"oneKan",
        component:OneKan
    },

    {
        path:"/openshop",
        name:"openshop",
        component:Openshop
    },
{
    path:"/helpCut",
    name:"helpCut",
    component:HelpCut
},
{
    path:"/business/:shopId",
    name:"business",
    component:Business
},
{
    path:"/cutCoin",
    name:"cutCoin",
    component:CutCoin
},
{
    path:"/rule",
    name:"rule",
    component:Rule
},
{
    path:"/balance",
    name:"balance",
    component:Balance
},
{
    path:"/surplusRule",
    name:"surplusRule",
    component:SurplusRule
},{
    path:"/newOrder",
    name:"newOrder",
    component:NewOrder
},
{
      path:'/aboutBlank',
      name:'aboutBlank',
      component:AboutBlank
},
    {
    path:"/success/:orderId",
    name:"success",
    component:SuccessOrder, 
},{
    path:"/redBag/:couponShareid",
    name:"redBag",
    component:RedBag, 
},{
    path:"/sign/:tag",
    name:"sign",
    component:Sign,
},{
    path:"/allorder/refund/:orderid/:Btype",
    name:"refunding",
    component:RefundPage
},{
    path:"/signGood",
    name:"signGood",
    component:SignGood
},{
    path:"/signRecord",
    name:"signRecord",
    component:SignRecord
},{
    path:"/assess",
    name:"assess",
    component:Assess
},{
    path:"/assSucc",
    name:"assSucc",
    component:AssSucc
},{
    path:"/addTo",
    name:"addTo",
    component:AddTo
},{
    path:"/allAssess/:pro_id",
    name:"allAssess",
    component:AllAssess
},{
    path:"/logistics/:orderid/:btType",
    name:"Logistics",
    component:Logistics
    },
{
    path:'/Cutzero/:tag',
    component:Cutzero
},
  {
    path:'/cutEight/:tag',
    name:"CutEight",
    component:CutEight
  }
,
{
    path:'/talking/activity',
    name:'activity',
    component:Activity
},
{
    path:'/allorder/flow/:orderid',
    name:'flow',
    component:Flow
},
{
    path:'/allorder/discuss/:orderid',
    name:'discuss',
    component:Discuss
},
{
    path:'/allorder/allLog/:orderid',
    name:'allLog',
    component:AllLog
},
{
    path:'/refund',
    name:'refund',
    component:Refund
},
{
    path:'/cutting',
    name:'cutting',
    component:Cutting
},
{
    path:'/lookMore/:id',
    name:'lookMore',
    component:LookMore
},
{   path:'/blank/:shareid',
    name:'blank',
    component:Blank
},
{
    path:'/newActivity',
    name:'newActivity',
    component:NewActivity
},
{
    path:'/threeKanRule',
    name:'threeKanRule',
    component:ThreeKanRule
},
  {
    path:'/cutVoucher/:tag',
    name:'cutVoucher',
    component:CutVoucher
  },
  {
    path:'/cutFree/:tag',
    name:'cutFree',
    component:CutFree
  },
  {
    path:'/index',
    name:'index',
    component:Index
  },
  {
    path:'/freeKan/:shareid',
    name:'freeKan',
    component:FreeKan
  },
  {
    path:'/killSecond/:tag',
    name:'killSecond',
    component:KillSecond
  },{
    path:'/khh',
    name:'khh',
    component:Khh
  },
  {
    path:'/swiperUrl',
    name:'swiperUrl',
    component:SwiperUrl
  },
];
// const router = new VueRouter({
//   mode: "history",
//   routes: routes,
//   scrollBehavior(to, from, savedPosition) {
//     if(savedPosition) {
//       return savedPosition
//     } else {
//       return {
//         x: 0,
//         y: 0
//       }
//     }
//   }
// });
//


var router = new VueRouter({
    routes:routes,
  //   mode: 'history',
  //history:true
  // scrollBehavior (to, from, savedPosition) {
  //   if (savedPosition) {
  //     return savedPosition
  //     alert("if");
  //   } else {
  //     if(from.meta.keepAlive) {
  //       from.meta.savedPosition = document.body.scrollTop;
  //       alert("else-if");
  //     }
  //     return { x: 0, y: to.meta.savedPosition || 0 };
  //     alert("else");
  //    }
  // }
})
new Vue({
    el: '#app',
    router:router,
    store,
    render: h => h(App),

    watch:{
        "$route":function(){
            var path = this.$route.path;
            switch (path){
                case "/home/index/00":
                    sessionStorage.setItem("cur",0)
                    this.cur = 0;
                    break;
                case "/home/newProduct":
                    sessionStorage.setItem("cur",1)
                    this.cur = 1;
                    break;
                case "/home/shopping":
                    sessionStorage.setItem("cur",2)
                    this.cur = 2;
                    break;
                case "/talking":
                    sessionStorage.setItem("cur",3)
                    this.cur = 3;
                    break;
                case "/home/my":
                    sessionStorage.setItem("cur",4)
                    this.cur = 4;
                    break;
                default:
                    break;
            }
        }
    }
})





